package sim;

import matrics.SparseVector;
import myLucene.GetTime;

public class Cosin {

	public static double getCosin(SparseVector verb, SparseVector target) {
//		Cosin.printSparseVector(verb);
//		Cosin.printSparseVector(target);
		double sim =0.0;
		long start = System.currentTimeMillis();
//		if(verb.norm()!=0.0){
//			System.out.println(" verb.norm() "+verb.norm());
//		}
//		if(target.norm()!=0){
//			System.out.println("target.norm() "+target.norm());
//		}
		if ((verb.norm() * target.norm()) ==0.0){
			sim = 0.0;

		}else{
		sim = verb.dot(target) / (verb.norm() * target.norm());
//		System.out.println("(verb.norm() * target.norm()) : "+verb.norm()+" " + target.norm());
		}
		//		System.out.println("getCosin...time needed...: "
//				+ GetTime.getDuration(start, System.currentTimeMillis()));
		return sim;
	}
	public static void printSparseVector(SparseVector sp){
		for(int i = 0; i<sp.size();i++){
		if (sp.get(i) !=0){
			System.out.println("printSparseVector "+sp.get(i) );
		}
		}
	}
}
